package zct.proj.util;

import java.util.HashMap;
import java.util.List;

import zct.proj.R;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class CustomAddedListAdapter extends BaseAdapter{
		 
    private LayoutInflater mInflater;
    private List<String> mData;
    private ListItemInterface ctx;
     
    public CustomAddedListAdapter(ListItemInterface context, List<String> data){
    	ctx = context;
        this.mInflater = LayoutInflater.from((Context) ctx);
        this.mData = data;
    }
    
    @Override
    public int getCount() {
        return mData.size();
    }
 
    @Override
    public Object getItem(int arg0) {
        return null;
    }
 
    @Override
    public long getItemId(int arg0) {
        return 0;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
             
        ViewHolder holder = null;
        if (convertView == null) {
             
            holder=new ViewHolder();  
             
            convertView = mInflater.inflate(R.layout.listitem, null);
            holder.title = (TextView)convertView.findViewById(R.id.title);
            holder.viewBtn = (Button)convertView.findViewById(R.id.view_btn);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
             
        holder.title.setText(mData.get(position));
		if (mData.get(position).endsWith("H")) {
			holder.title.setTextColor(Color.RED);
		} else {
			holder.title.setTextColor(Color.WHITE);
		}
        holder.viewBtn.setText("取消");
        holder.viewBtn.setTag(mData.get(position));

    	holder.viewBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ctx.itemButtonClicked(v);
            }
        });

        return convertView;
    }
}